package com.homedo.odin.solution.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.homedo.core.common.base.service.BaseService;
import com.homedo.core.common.util.BeanUtils;
import com.homedo.odin.solution.dao.UserColumnMapper;
import com.homedo.odin.solution.model.entity.UserColumn;
import com.homedo.odin.solution.model.request.pc.collect.UserCollectColumnRequestBean;
import com.homedo.odin.solution.model.response.pc.collect.MyColumnCollectPageResponseBean;
import com.homedo.odin.solution.model.response.pc.collect.MyColumnCollectResponseBean;
import org.springframework.stereotype.Service;

/**
 * <p> 用户与栏收藏关系表 服务实现类 </p>
 *
 * @author HarveyDing
 * @since 2018-03-08
 */
@Service
public class UserColumnServiceImpl extends BaseService<UserColumnMapper, UserColumn> {

    public UserColumn getUserSpecialColumn(Integer userId, Long columnId, Integer actionType) {
        return baseMapper.getUserSpecialColumn(userId, columnId, actionType);
    }

    public void addUserColumn(UserColumn uColumn) {
        baseMapper.insert(uColumn);
    }

    public void updateUserColumn(UserColumn userColumn) {
        baseMapper.updateById(userColumn);
    }


    /**
     * PC_获取收藏的资讯列表
     */
    public MyColumnCollectPageResponseBean getColumnCollectList(UserCollectColumnRequestBean requestBean) {
        PageInfo<MyColumnCollectResponseBean> pageInfo = PageHelper
                .startPage(requestBean.getPageNum(), requestBean.getPageSize())
                .doSelectPageInfo(() -> baseMapper
                        .getByUidLeftJionColution(requestBean.getUserId(), requestBean.getStartDate(),
                                requestBean.getEndDate()));
        return BeanUtils.transfrom(MyColumnCollectPageResponseBean.class, pageInfo);
    }
}
